from trade.models import CostDetails
from utils.time import getCurrentTime
from rest_framework.response import Response
from rest_framework import status
import random


def get_cost_price(date=getCurrentTime(format="%Y-%m-%d")):
    try:
        cost_list = CostDetails.objects.get(date=date, status=1)

    except:
        cost_list = CostDetails.objects.last()

    eq_cost = {
        '0': cost_list.eight_cabinet,
        '1': cost_list.sixteen_cabinet,
        '2': cost_list.sixteen_cabinet_oneBody,
        '3': cost_list.thirty_two_cabinet,
        '4': cost_list.forty_eight_cabinet,
        '5': cost_list.power_bank
    }
    return eq_cost


"""发短信接口"""

# def sms_send(phone, code):
#     client = AcsClient("<AccessKeyId>", "<AccessKeySecret>", "cn-hangzhou")
#     request = CommonRequest()
#     request.set_accept_format('json')
#     request.set_domain('dysmsapi.aliyuncs.com')
#     request.set_protocol_type('https')  # https | http
#     request.set_version('2017-05-25')
#     request.set_action_name('SendSms')
#     request.add_query_param('PhoneNumbers', phone)
#     request.add_query_param('SignName', '北网')
#
#     request.add_query_param('TemplateCode', 'SMS_162738723')
#     request.add_query_param('TemplateParam', code)
#     response = client.do_action(request)
#
#     request.add_query_param('RegionId', "cn-hangzhou")
#     return str(response, encoding='utf-8')


"""随机验证码"""


def get_code(n=6, alpha=True):
    s = ''  # 创建字符串变量,存储生成的验证码
    for i in range(n):  # 通过for循环控制验证码位数
        num = random.randint(0, 9)  # 生成随机数字0-9
        if alpha:  # 需要字母验证码,不用传参,如果不需要字母的,关键字alpha=False
            upper_alpha = chr(random.randint(65, 90))
            lower_alpha = chr(random.randint(97, 122))
            num = random.choice([num, upper_alpha, lower_alpha])
        s = s + str(num)
    return s


"""退款"""

#
# def back(req, trade, resp):
#
